﻿using System;
using System.Collections.Generic;
using TopBuilds.Restaurant.Data;

namespace TopBuilds.Restaurant.ManagementClient
{
    public sealed class PrintTemplateCollection : System.Collections.ObjectModel.ObservableCollection<PrintTemplate>
    {
        private string _condition;

        public string Condition
        {
            get { return _condition; }

            set
            {
                if (_condition != null && _condition == value)
                {
                    return;
                }

                _condition = value;

                if (Count > 0)
                {
                    base.Clear();
                }

                PrintTemplate[] list = PrintTemplateObject.GetPrintTemplates();
                if (list != null)
                {
                    foreach (PrintTemplate template in list)
                    {
                        base.Add(template);
                    }
                }
            }
        }

        public PrintTemplateCollection()
        {
            Condition = null;
        }

        public PrintTemplate GetPrintTemplate(int printTemplateId)
        {
            foreach (PrintTemplate printTemplate in this)
            {
                if (printTemplate.Id == printTemplateId)
                {
                    return printTemplate;
                }
            }

            return null;
        }

    }
}
